package com.nuc.bigdata.feign;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.nuc.bigdata.exception.BusinessException;
import com.nuc.bigdata.feign.dto.NewsCommentsDto;
import com.nuc.bigdata.feign.entity.CommentsFeign;
import com.nuc.bigdata.feign.entity.CommodityCommentsFeign;
import com.nuc.bigdata.feign.entity.PhotoNewsCommentsFeign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * 调用oa-comments服务的feign客户端
 * @author JackLuo
 * @date 2019/11/20
 */
@FeignClient(name = "oa-comments")
public interface NewsCommentsServiceFeign {

    /**
     * 获取指定新闻id的评论feign的ArrayList
     * @param newsId 新闻唯一标识
     * @param pageSize 页码
     * @return 提供给front服务的新闻评论ArrayList
     */
    @GetMapping("/oa-comments/{newsId}")
    ArrayList<CommentsFeign> queryCommentsFeign(@PathVariable("newsId") String newsId,
                                                @RequestParam("pageSize") Long pageSize);
    /**
     * 创建新闻评论
     * @param newsId 新闻唯一标识
     * @param commentsDto 评论类包含userId和content
     */
    @PostMapping("/oa-comments/{newsId}")
    void createComments(@PathVariable("newsId") String newsId,
                        @RequestBody NewsCommentsDto commentsDto);

    /**
     * 点赞新闻评论
     * @param commentId 评论唯一标识
     * @param userId 用户唯一标识
     */
    @PostMapping("/oa-comments/{commentId}/like")
    @HystrixCommand(ignoreExceptions = BusinessException.class)
    void toCommentLike(@PathVariable("commentId") String commentId,
                       @RequestParam("userId") String userId);


    /**
     * 创建新闻资讯评论
     * @param pnId 新闻资讯唯一标识
     * @param commentsDto 评论类包含userId和content
     */
    @PostMapping("/oa-comments/photos/{pnId}")
    void createPhotosComments(@PathVariable("pnId") String pnId,
                              @RequestBody NewsCommentsDto commentsDto);

    /**
     * 获取指定图片资讯的评论ArrayList
     * @param pnId 图片资讯唯一标识
     * @param pageSize 页码
     * @return 提供给front服务的评论feign的ArrayList
     */
    @GetMapping("/oa-comments/photos/{pnId}")
    ArrayList<PhotoNewsCommentsFeign> queryPhotosCommentsFeign(@PathVariable("pnId") String pnId,
                                                               @RequestParam("pageSize") Long pageSize);

    /**
     * 点赞图片评论
     * @param photoCommentId 图片评论唯一标识
     * @param userId 用户唯一标识
     */
    @PostMapping("/oa-comments/photos/{photoCommentId}/like")
    @HystrixCommand(ignoreExceptions = BusinessException.class)
    void toPhotoCommentLike(@PathVariable("photoCommentId") String photoCommentId,
                            @RequestParam("userId") String userId);


    /**
     * 创建新评论
     * @param commodityId 商品唯一标识
     * @param commentsDto 评论dto
     */
    @PostMapping("/oa-comments/commodity/{commodityId}")
    void createCommodityComments(@PathVariable("commodityId")String commodityId,
                                        @RequestBody NewsCommentsDto commentsDto) ;

    /**
     * 获取商品评论信息
     * @param commodityId 商品唯一标识
     * @param pageSize 页码
     * @return 包含商品评论feign的ArrayList
     */
    @GetMapping("/oa-comments/commodity/{commodityId}")
    ArrayList<CommodityCommentsFeign> queryCommodityCommentsFeign(@PathVariable("commodityId")String commodityId,
                                                                         @RequestParam("pageSize") Long pageSize);

    /**
     * 点赞用户评论
     * @param commodityCommentId 评论唯一标识
     * @param userId 用户唯一标识
     */
    @PostMapping("/oa-comments/commodity/{commodityCommentId}/like")
    void toCommodityCommentLike(@PathVariable("commodityCommentId")String commodityCommentId,
                                       @RequestParam("userId") String userId);
}